#include <stdafx.h>

#define GLUT_DISABLE_ATEXIT_HACK
#ifdef __APPLE__
	#include <GLUT/glut.h>
#else
	#include <GL/glut.h>
#endif

#define window_width  640
#define window_height 480
// Main loop

#include <Game.h>
#include "cl_test.h"

Game* gGame;
bool bInit = false;
float lastTime = 0;
void reshape_func(const int width, const int height)
{
	gGame->surface_changed(width, height);
	bInit = true;
}
void render_func()
{
	if (!bInit) return;
	float curTime = (float)glutGet(GLUT_ELAPSED_TIME)/1000.0f;
	gGame->render(curTime - lastTime);
	lastTime = curTime;
	glutSwapBuffers();
}

void mouse_func(int button, int state, int x, int y){
	if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){
		gGame->touch((float)x/gGame->getWidth(),(float)y/gGame->getHeight());
	}
}

// Initialize GLUT and start main loop
int main(int argc, char** argv) {
	//cl_test
#ifndef _ANDROID
	CL_Test* a = new CL_Test();
#endif

	glutInit(&argc, argv);
	glutInitWindowSize(window_width, window_height);
	glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
	glutCreateWindow("GLUT example");

#ifdef __CYGWIN32__
	glewInit();
    if (glewIsSupported("GL_VERSION_2_0"))
        LOGI("Ready for OpenGL 2.0\n");
    else {
    	LOGI("OpenGL 2.0 not supported\n");
    }
#endif
	glutDisplayFunc(render_func);
	glutIdleFunc(render_func);
	glutReshapeFunc(reshape_func);
	glutMouseFunc(mouse_func);

	gGame = new Game();
	glutMainLoop();
	delete gGame;
}

